<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../lib/layui-v2.5.5/css/layui.css" media="all">
    <link rel="stylesheet" href="../css/public.css" media="all">
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body>
<div class="layui-form layuimini-form">
	
	        <input type="hidden" name="id" lay-verify="required"  value="" class="layui-input">
	 
	
	<div class="layui-form-item">
	    <label class="layui-form-label required">标题图片地址</label>
	    <div class="layui-input-block">
	        <input type="text" name="comimg"  id="uImg2" value="" class="layui-input">
			<img id="uImg" style="width: 100px; height: 100px;" src="" />
	        <tip>填写自己管理图片路径的信息。</tip>
	    </div>
	</div>
	
		<div class="layui-form-item">
	    <label class="layui-form-label required">图文详解图片地址</label>
	    <div class="layui-input-block">
	        <input type="text" name="comimgs"value="" id="uImg4" class="layui-input">
			<img id="uImg3" style="width: 100px; height: 100px;" src="" />
	        <tip>填写自己管理价格的信息。</tip>
	    </div>
	</div>
	
	
	<div class="layui-form-item">
	    <label class="layui-form-label required">上传标题图片</label>
	    <div class="layui-input-block">
	       <button type="button" class="layui-btn" id="test1">
	       	<i class="layui-icon">&#xe67c;</i>上传标题图片
	       </button>
	    </div>
	</div>
	
	
	<div class="layui-form-item">
	    <label class="layui-form-label required">上传图文详解图片</label>
	    <div class="layui-input-block">
	       <button type="button" class="layui-btn" id="test2">
	       	<i class="layui-icon">&#xe67c;</i>上传图文详解图片
	       </button>
	    </div>
	</div>
	
	

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="saveBtn">确认保存</button>
        </div>
    </div>
</div>
</div>
<script src="../lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
<script>
    layui.use(['form','upload','layedit'], function () {
        var form = layui.form,
            layer = layui.layer,
            $ = layui.$;
			upload =layui.upload;
				
				var uploadInst =upload.render({
					elem:'#test1',
					url:'http://localhost:8085/shop/uploadImg',
					data:{
						url:function(){
							return $("#uImg").attr("src").replace("http://47.114.97.182/","");
						}
					},
					done:function(res){
						$("#uImg").attr("src","http://47.114.97.182/"+res.data)
						$("#uImg2").val("http://47.114.97.182/"+res.data)
						console.log(res)
					},
					error:function(){
						alert("上传失败，请联系管理员")
					}
				});
				var uploadInst =upload.render({
					elem:'#test2',
					url:'http://localhost:8085/shop/uploadImg',
					data:{
						url:function(){
							return $("#uImg3").attr("src").replace("http://47.114.97.182/","");
						}
					},
					done:function(res){
						$("#uImg3").attr("src","http://47.114.97.182/"+res.data),
						$("#uImg4").val("http://47.114.97.182/"+res.data),
						console.log(res)
					},
					error:function(){
						alert("上传失败，请联系管理员")
					}
				});
			
        //监听提交
        form.on('submit(saveBtn)', function (data) {
            var index = layer.alert('是否提交', {
                title: '确定'
            }, function () {
              // ajax
              $.post("http://localhost:8085/shop/updateImg",data.field,
                (res) =>{
              	    // 关闭弹出层
              		layer.close(index);
              		var iframeIndex = parent.layer.getFrameIndex(window.name);
              		parent.layer.close(iframeIndex);  
              }
              )

            });

            return false;
        });

    });
</script>
</body>
</html>